﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vanfa.Queries.Sql.DbModel;
using Vanfa.Entities.User;

namespace Vanfa.Biz.User
{
    /// <summary>
    /// 业务实体转换成数据对象
    /// </summary>
    public static partial class BizConverter
    {
        public static userMember ToDbEntity(this vRegist rg)
        {
            var u = new userMember
            {
                UserName = rg.UserName,
                Password = rg.Md5Pwd,
                Mobile = rg.MobileNumber,
                GradeID = (int)rg.Grade,
                UserType = (int)rg.Type,
                Gender = rg.Gender == EU_UserGender.Man,
                RegistTime = DateTime.Now,
                LatestLoginTime = DateTime.Now
            };
            return u;
        }

        public static userMemberInfo_Private ToDbEntity_up(this vUserPrivInfo up)
        {
            var ump = new userMemberInfo_Private
            {
                Birthday = up.Birthday,
                Career = "",
                FullName = up.FullName,
                HomeTown = up.Location,
                IconPath = up.Icon,
                IDCard = up.IDCard,
                NickName = up.NickName,
                UserID = up.UserID,
                WorkPlace1 = "",
                WorkPlace2 = ""
            };
            return ump;
        }

        public static userMemberInfo_Contact ToDbEntity_uc(this vUserPrivInfo up)
        {
            var uc = new userMemberInfo_Contact
            {
                Email = up.Email,
                MobilePhone = up.Mobile1,
                iPhone = up.Mobile2,
                MSN = "",
                QQ = up.QQ,
                QqWebo = "",
                SinaWebo = up.WBo,
                UserID = up.UserID,
                Wechat = up.WChat
            };
            return uc;
        }

        public static userMemberFilter ToDbEntity_uf(this vUserPrivInfo up)
        {
            var uf = new userMemberFilter
            {
                Height = up.Height,
                P1 = up.P1,
                P2 = up.P2,
                P3 = up.P3,
                P4 = up.P4,
                P5 = up.P5,
                P6 = up.P6,
                P7 = up.P7,
                UserID = up.UserID,
                Weight = up.Weight
            };
            return uf;
        }

        public static userMemberInfo_Contact ToDbEntity_uc(this vUserGroupInfo ug)
        {
            var uc = new userMemberInfo_Contact
            {
                Email = ug.Email,
                MobilePhone = ug.Mobile1,
                iPhone = ug.Mobile2,
                MSN = "",
                QQ = ug.QQ,
                QqWebo = "",
                SinaWebo = ug.Weibo,
                UserID = ug.UserID,
                Wechat = ug.WebChat
            };
            return uc;
        }

        public static userMemberInfo_Group ToDbEntity_up(this vUserGroupInfo ug)
        {
            var uc = new userMemberInfo_Group
            {
                Agent = ug.Agent,
                FoundTime = ug.FunDate,
                GroupName = ug.GourpName,
                GroupType = ug.GroupType,
                IDCard = ug.IDCard,
                MemberCount = ug.GroupCount,
                Memo = "",
                UserID = ug.UserID,
                WorkPlace1 = "",
                WorkPlace2 = "",
                IconPath = ug.Icon
            };
            return uc;
        }
    }
}
